<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\business\EhrHelper;

/* @var $this yii\web\View */
/* @var $searchModel common\models\EmployeeDepartmentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Employee Departments');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="employee-department-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Employee Department'), ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a(Yii::t('app', 'Sync Employee Department Relation From HR'), ['sync-from-hr'], ['class' => 'btn btn-primary', 'target'=>'_blank']) ?>
    </p>
    <?php
    try {
        $gv = GridView::widget([
            'tableOptions' => ['class' => 'table table-condensed table-bordered table-striped table-hover'],
            'pager' => [
//            'class'          => GoPager::className(),
                'nextPageLabel'  => Yii::t('app', 'Next Page'),
                'prevPageLabel'  => Yii::t('app', 'Previous Page'),
                'firstPageLabel' => Yii::t('app', 'First Page'),
                'lastPageLabel'  => Yii::t('app', 'Last Page'),
                'options' => [
                    'class' => 'pagination pagination-sm m-t-none m-b-none',
                ],
            ],
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                [
                    'class' => 'yii\grid\SerialColumn',
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
                ],

//                'id',
                [
                    'attribute' => 'employee_number',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 180px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 180px;'],
                ],
                [
                    'label' => Yii::t('app', 'Employee'),
                    'attribute' => 'employee_name',
                    'value' => function ($model) {
                        return Html::a($model['employee_name'], [
                            '/employee/view',
                            'id' => $model['employee_id'],
                        ],
                            ['target' => '_blank']);
                    },
                    'format' => 'raw',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 280px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 280px;'],
                ],
                [
                    'attribute' => 'level',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                [
                    'label' => Yii::t('app', 'Department Name'),
                    'attribute' => 'department_name',
                    'value' => function ($model) {
                        return Html::a($model['department_name'], [
                            '/department/view',
                            'id' => $model['department_id'],
                        ],
                            ['target' => '_blank']);
                    },
                    'format' => 'raw',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                [
                    'label' => Yii::t('app', 'Department Number'),
                    'attribute' => 'department_number',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                [
                    'label' => Yii::t('app', 'HR Sync Status'),
                    'attribute' => 'hr_status',
                    'value' => function ($model, $key, $index, $column) {
                        return EhrHelper::getSyncStatusByIntValue($model['hr_status']);
                    },
                    'filter' => EhrHelper::getSyncStatus_map(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
                [
                    'label' => Yii::t('app', 'Qywx Sync Status'),
                    'attribute' => 'qywx_status',
                    'value' => function ($model, $key, $index, $column) {
                        return EhrHelper::getSyncStatusByIntValue($model['qywx_status']);
                    },
                    'filter' => EhrHelper::getSyncStatus_map(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                ],
                [
                    'label' => Yii::t('app', 'Created At'),
                    'attribute' => 'created_by',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                [
                    'label' => Yii::t('app', 'Updated At'),
                    'attribute' => 'updated_at',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
//                'created_at',
                // 'updated_by',
                // 'updated_at',

                ['class' => 'yii\grid\ActionColumn'],
            ],
        ]);
    } catch (Exception $e) {
    }
    ?>
    <?= $gv ?>
</div>
